//
// Created by 段大志 on 16/4/23.
// Copyright (c) 2016 BMProject. All rights reserved.
//

#import "BackgroundBizCell.h"
#import "DataModel.h"
#import "NSDate+Utils.h"

@interface BackgroundBizCell(){

}
@property (weak, nonatomic) IBOutlet UIView *bgView;//背景
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;//标题
@property (weak, nonatomic) IBOutlet UILabel *contentLabel;//内容
@property (weak, nonatomic) IBOutlet UILabel *sponsorLabel;//发起人
@property (weak, nonatomic) IBOutlet UILabel *stateLabel;//状态
@property (weak, nonatomic) IBOutlet UILabel *timeLabel;//时间

@end

@implementation BackgroundBizCell {

}

- (void)awakeFromNib {
    [super awakeFromNib];
    self.bgView.layer.cornerRadius = 5.0;
    self.bgView.layer.masksToBounds = YES;
}

-(void)setCellInfo:(BlackListWrapModel *)info andPosition:(NSInteger)position{
    BlackListModel *blackListModel = info.blackListModels[position];
    if (blackListModel) {
        self.titleLabel.text    = [NSString stringWithFormat:@"标题:%@", [NSString ignoreEmptyStr:blackListModel.title]];
        self.contentLabel.text  = [NSString stringWithFormat:@"内容:%@", [NSString ignoreEmptyStr:blackListModel.message]];
        NSString *stateStr = @"";
        if (blackListModel.sign.intValue == 0) { // 0,1 2 待回复   未处理  已处理
            stateStr = @"待回复";
            [self.dealBtn setTitle:@"回复" forState:UIControlStateNormal];
        } else if (blackListModel.sign.intValue == 2) {
            stateStr = @"已回复";
            [self.dealBtn setTitle:@"回复" forState:UIControlStateNormal];
        } else {
            [self.dealBtn setTitle:@"处理" forState:UIControlStateNormal];
            stateStr = @"未处理";
        }
        self.stateLabel.text    = [NSString stringWithFormat:@"状态:%@", [NSString ignoreEmptyStr:stateStr]];//状态
        self.timeLabel.text     = [NSString stringWithFormat:@"时间:%@", [NSString ignoreEmptyStr: ([[NSDate dateWithString:blackListModel.creatTime formatString:@"yyyyMMddHHmmss"] formatStringWithFormat:@"yyyy-MM-dd"]) ]];//时间
    } else {
        self.titleLabel.text    = [NSString stringWithFormat:@"标题:%@", [NSString ignoreEmptyStr:@""]];
        self.contentLabel.text  = [NSString stringWithFormat:@"内容:%@", [NSString ignoreEmptyStr:@""]];
        self.stateLabel.text    = [NSString stringWithFormat:@"状态:%@", [NSString ignoreEmptyStr:@""]];
        self.timeLabel.text     = [NSString stringWithFormat:@"时间:%@", [NSString ignoreEmptyStr:@""]];
    }

    BOOL         isHave = NO;
    NSString *key_value = @"";
    for (int i = 0; i < info.dictionary.count; ++i) {
        NSDictionary *dict = info.dictionary[i];
        if (dict && dict.allKeys.count > 0) {
           NSString *key    = dict.allKeys[0];
           NSString *value  = dict[key];
            if ([key isEqualToString:blackListModel.userId]) {
                isHave = YES;
                key_value = value;
                break;
            }
        }
    }
    if (isHave) {
        self.sponsorLabel.text = [NSString stringWithFormat:@"发起人:%@", [NSString ignoreEmptyStr:key_value]];
    } else {
        self.sponsorLabel.text = @"发起人:";
    }
}

@end